<style lang="scss" scoped>
</style>

<template>
  <div class="infobody">
    <top-bar @partToggle="partToggle" @toggleEditStatus="toggleEditStatus" @saveItem="saveItem" @saveTemp="saveTemp" @clickNextStep="clickNextStep"  ref="topbar"></top-bar>
    <div class="content">
      <loading v-model="spinShow"></loading>
      <p class="form-title">{{formTitle}}</p>
      <div id="part1" v-show="partShow" >                     
        <Form :model="knubSampleModel" ref="knubSampleModelOne" :rules="ruleFormOne"  >                      
            <div class="title">
                个人信息
                <span class="title-right" @click="personToggle=!personToggle" v-show="personToggle"><Icon type="minus-round"></Icon></span>
                <span class="title-right" @click="personToggle=!personToggle" v-show="!personToggle"><Icon type="plus-round"></Icon></span>  
            </div>
            <div class="info" v-show="personToggle">
                <FormItem label="userId" hidden>
                    <Input v-model="knubSampleModel.tKnubSampleEntity.userId" />
                </FormItem> 
                <FormItem label="姓名" prop="tKnubSampleEntity.name">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.name" placeholder="请输入姓名" />
                </FormItem>
                <FormItem label="性别" prop="tKnubSampleEntity.sex">
                    <Select :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.sex" placeholder="请选择性别">
                        <Option value="男">男</Option>
                        <Option value="女">女</Option>
                    </Select>
                </FormItem>
                <FormItem label="出生日期" prop="tKnubSampleEntity.birthday">
                  <div class="ivu-input-wrapper ivu-input-type">
                      <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmDate('birthday')">
                        <span v-if="knubSampleModel.tKnubSampleEntity.birthday">{{knubSampleModel.tKnubSampleEntity.birthday}}</span>
                        <span v-else   style="color:#bbbec4;">请选择出生日期</span>
                      </div>
                  </div>    
                </FormItem>
                <FormItem label="样本编号">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.sampleNum" placeholder="请输入样本编号" />
                </FormItem>
                <FormItem label="民族">
                  <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.nation" placeholder="请输入民族" />
                </FormItem>
                <FormItem label="电话" prop="tKnubSampleEntity.tel">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.tel" placeholder="请输入电话" />
                </FormItem>
                <FormItem label="身份证号" prop="tKnubSampleEntity.idCard">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.idCard" placeholder="请输入身份证号" />
                </FormItem>
                <FormItem label="籍贯">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.origin" placeholder="请输入籍贯" />
                </FormItem>
                <FormItem label="地址">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.address" placeholder="请输入地址" />
                </FormItem>      
                <FormItem label="送检单位">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.company" placeholder="请输入送检单位" />
                </FormItem>
                <FormItem label="送检科室">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.section" placeholder="请输入送检科室" />
                </FormItem>
                <FormItem label="送检医生">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.doctor" placeholder="请输入送检医生" />
                </FormItem>  
                <FormItem label="医生电话">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.doctorTel" placeholder="请输入医生电话" />
                </FormItem>
                <FormItem label="住院号">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.admission" placeholder="请输入住院号" />
                </FormItem>   
                <FormItem label="采样日期" prop="tKnubSampleEntity.sampleDate">
                    <div class="ivu-input-wrapper ivu-input-type">
                      <div v-bind:class="{'div-disabled':status,'ivu-input':true}" @click="confirmDate('sampleDate')">
                        <span v-if="knubSampleModel.tKnubSampleEntity.sampleDate">{{knubSampleModel.tKnubSampleEntity.sampleDate}}</span>
                        <span v-else   style="color:#bbbec4;">请选择采样日期</span>
                      </div>
                    </div>    
                </FormItem>
                <FormItem label="是否吸烟" >
                    <Select :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.isOrSmoke" placeholder="请选择是否吸烟">
                        <Option value="是">是</Option>
                        <Option value="否">否</Option>
                    </Select>
                </FormItem>  
                  <FormItem label="癌症年龄" prop="tKnubSampleEntity.ageCancer">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.ageCancer" placeholder="请输入癌症年龄" number />
                </FormItem>   
                  <FormItem label="病理诊断" prop="tKnubSampleEntity.pathologicDiagnosis"> 
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.pathologicDiagnosis" placeholder="请输入病理诊断" />
                </FormItem>  
                  <FormItem label="临床分期" prop="tKnubSampleEntity.clinicalStages">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.clinicalStages" placeholder="请输入临床分期" />
                </FormItem>  
                  <FormItem label="既往分子检测结果" prop="tKnubSampleEntity.detectionResults">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.detectionResults" type="textarea" placeholder="请输入既往分子检测结果" />
                </FormItem>   
                <FormItem label="临床诊断" prop="tKnubSampleEntity.clinicalDiagnosis">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.clinicalDiagnosis" type="textarea"  placeholder="请输入临床诊断" />  
                </FormItem>
                <FormItem label="药物史" prop="tKnubSampleEntity.medicineHistory">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.medicineHistory" type="textarea"  placeholder="请输入药物史" />
                </FormItem>   
                <FormItem label="补送样本">
                  <Select :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.replacesample">
                        <Option value="是">是</Option>
                        <Option value="否">否</Option>
                    </Select>
                </FormItem>
                <FormItem label="科研样本">
                    <Select :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.researchsample">
                        <Option value="是">是</Option>
                        <Option value="否">否</Option>
                    </Select>
                </FormItem>
            </div>
            <div class="title">
                临床信息
                <span class="title-right" @click="familyToggle=!familyToggle" v-show="familyToggle"><Icon type="minus-round"></Icon></span>
                <span class="title-right" @click="familyToggle=!familyToggle" v-show="!familyToggle"><Icon type="plus-round"></Icon></span>   
            </div>
            <div class="info" v-show="familyToggle">
                <div v-for="(item, index) in knubSampleModel.tClinicInfoEntity" :key="index">
                    <FormItem label="个人或家族病史" :prop="'tClinicInfoEntity.' + index + '.familyHistory'"  :rules="{required:true,message:'个人或家族病史不能为空',trigger:'blur'}">
                        <Input :disabled="status" v-model="item.familyHistory" type="textarea"  placeholder="请输入个人或家族病史" />  
                    </FormItem>
                    <FormItem label="样本类型" :prop="'tClinicInfoEntity.' + index + '.cliSampleTypeArray'"  :rules="{required:true,type:'array',message:'样本类型不能为空',trigger:'change'}" >            
                        <CheckboxGroup v-model="item.cliSampleTypeArray">
                          <Checkbox label="石蜡包埋组织/切片" :disabled="status"></Checkbox>
                          <Checkbox label="手术/穿刺组织" :disabled="status"></Checkbox>
                          <Checkbox label="胸/腹水" :disabled="status"></Checkbox>
                          <Checkbox label="EDTA抗凝" :disabled="status"></Checkbox>
                          <Checkbox label="Streck管" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                        </CheckboxGroup>
                    </FormItem>
                    <FormItem  v-show="item.cliSampleTypeArray? item.cliSampleTypeArray.indexOf('其他')!=-1 : false">   
                        <Input :disabled="status" v-model="item.itsCliSampleType"  placeholder="请输入样本类型" />
                    </FormItem> 
                      <FormItem label="样本来源" :prop="'tClinicInfoEntity.' + index + '.sampleSource'"  :rules="{required:true, message:'样本来源不能为空',trigger:'change'}">                      
                        <Select :disabled="status" v-model="item.sampleSource" placeholder="请选择样本来源">
                            <Option value="原发灶">原发灶</Option>
                            <Option value="转移灶">转移灶</Option>
                            <Option value="其他">其他</Option>
                        </Select>
                    </FormItem>  
                    <FormItem  v-show="item.sampleSource=='转移灶'">   
                        <Input :disabled="status" v-model="item.metastasis"  placeholder="请输入转移灶" />
                    </FormItem>  
                      <FormItem  v-show="item.sampleSource=='其他'">   
                        <Input :disabled="status" v-model="item.itsSampleSource"  placeholder="请输入其他" />
                    </FormItem>  
                    <FormItem label="传染病原检测阳性" :prop="'tClinicInfoEntity.' + index + '.masculineDetectionArray'" :rules="{required:true,type:'array',message:'传染病原检测阳性不能为空',trigger:'change'}">            
                        <CheckboxGroup v-model="item.masculineDetectionArray">
                          <Checkbox label="无" :disabled="status"></Checkbox>
                          <Checkbox label="乙肝" :disabled="status"></Checkbox>
                          <Checkbox label="丙肝" :disabled="status"></Checkbox>
                          <Checkbox label="梅毒" :disabled="status"></Checkbox>
                          <Checkbox label="HIV" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                        </CheckboxGroup>
                    </FormItem>
                    <FormItem  v-show="item.masculineDetectionArray?item.masculineDetectionArray.indexOf('其他')!=-1:false">   
                        <Input :disabled="status" v-model="item.itsMasculineDetection"  placeholder="请输入传染病原检测阳性" />
                    </FormItem>                               
                      <FormItem label="特殊情况说明" :prop="'tClinicInfoEntity.' + index + '.exceptionalCase'"  :rules="{required:true, message:'特殊情况说明不能为空',trigger:'change'}">                      
                        <Select :disabled="status" v-model="item.exceptionalCase" placeholder="请选择特殊情况说明">
                            <Option value="返样">返样</Option>
                            <Option value="其他">其他</Option>
                            <Option value="无">无</Option>
                        </Select>
                    </FormItem>  
                      <FormItem  v-show="item.exceptionalCase=='其他'">   
                        <Input :disabled="status" v-model="item.itsExceptionalCase"  placeholder="请输入特殊情况说明" />
                    </FormItem>                                  
                </div>
            </div>

            <div class="title">
                检测项目
                <span class="title-right" @click="projectToggle=!projectToggle" v-show="projectToggle"><Icon type="minus-round"></Icon></span>
                <span class="title-right" @click="projectToggle=!projectToggle" v-show="!projectToggle"><Icon type="plus-round"></Icon></span> 
            </div>
            <div class="info" v-show="projectToggle">
              <div class="note" style="color:#ed3f14">（注：检测项目至少要填一项）</div>
                <div v-for="(item, index) in knubSampleModel.tKnubProjectList" :key="index">
                    <FormItem label="泛癌种panel" :prop="'tKnubProjectList.' + index + '.pannelArray'"  >
                      <CheckboxGroup v-model="item.pannelArray">
                          <Checkbox label="实体瘤618基因" :disabled="status"></Checkbox>
                          <Checkbox label="全肿瘤个性化用药90基因" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                      </CheckboxGroup>
                    </FormItem>
                    <FormItem v-show="item.pannelArray?item.pannelArray.indexOf('其他')!=-1:false">
                        <Input :disabled="status" v-model="item.itsPannel" placeholder="请输入泛癌种panel" />
                    </FormItem>  

                    <FormItem ref="popRef" label="单癌种检测" :prop="'tKnubProjectList.' + index + '.singleCancerArray'" > 
                      <CheckboxGroup v-model="item.singleCancerArray">
                          <Checkbox label="肺癌8基因" :disabled="status"></Checkbox>
                          <Checkbox label="肺癌8基因+PDL1" :disabled="status"></Checkbox>
                          <Checkbox label="肺癌56基因" :disabled="status"></Checkbox>
                          <Checkbox label="结直肠癌42基因" :disabled="status"></Checkbox>                                                                 
                          <Checkbox label="乳腺癌62基因" :disabled="status"></Checkbox>
                          <Checkbox label="淋巴瘤105基因" :disabled="status"></Checkbox>
                          <Checkbox label="肾癌82基因" :disabled="status"></Checkbox>
                          <Checkbox label="结直肠癌BRAF+KRAS+NRAS+MSI" :disabled="status"></Checkbox>
                          <Checkbox label="脑胶质瘤62基因(含MGMT甲基化)" :disabled="status"></Checkbox>                                 
                          <Checkbox label="甲状腺瘤32基因" :disabled="status"></Checkbox>                                   
                          <Checkbox label="胃肠间质瘤22基因" :disabled="status"></Checkbox>
                          <Checkbox label="胰腺癌46基因" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                      </CheckboxGroup>
                    </FormItem>
                    <FormItem v-show="item.singleCancerArray?item.singleCancerArray.indexOf('其他')!=-1:false">
                        <Input :disabled="status" v-model="item.itsSingleCancer" placeholder="请输入单癌种检测" />
                    </FormItem>  

                    <FormItem label="靶向用药检测" :prop="'tKnubProjectList.' + index + '.targetedDrugArray'"  >
                      <CheckboxGroup v-model="item.targetedDrugArray">
                          <Checkbox label="EGFR基因突变(病理组织)" :disabled="status"></Checkbox>
                          <Checkbox label="EGFR基因突变(血浆ctDNA)" :disabled="status"></Checkbox>
                          <Checkbox label="EGFR基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="KRAS基因突变" :disabled="status"></Checkbox>
                          <Checkbox label="Nras基因突变" :disabled="status"></Checkbox>
                          <Checkbox label="BRAF基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="PIK3CA基因突变" :disabled="status"></Checkbox>
                          <Checkbox label="HER2-neu基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="HER2-neu基因扩增" :disabled="status"></Checkbox>
                          <Checkbox label="VEGFR1基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="VEGFR2基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="PDGFR α 基因突变" :disabled="status"></Checkbox>
                          <Checkbox label="PDGFR β 基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="C-Kit基因突变" :disabled="status"></Checkbox>
                          <Checkbox label="EML4-ALK融合基因" :disabled="status"></Checkbox>
                          <Checkbox label="c-Met基因表达" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                      </CheckboxGroup>
                    </FormItem>  
                    <FormItem v-show="item.targetedDrugArray?item.targetedDrugArray.indexOf('其他')!=-1:false">
                        <Input :disabled="status" v-model="item.itsTargetedDrug" placeholder="请输入靶向用药检测" />
                    </FormItem>  

                    <FormItem label="其他" :prop="'tKnubProjectList.' + index + '.otherArray'"  >
                      <CheckboxGroup v-model="item.otherArray">
                          <Checkbox label="化疗套餐" :disabled="status"></Checkbox>
                          <Checkbox label="乳腺癌21基因" :disabled="status"></Checkbox>
                          <Checkbox label="MSI" :disabled="status"></Checkbox>                                    
                          <Checkbox label="Septin9基因甲基化" :disabled="status"></Checkbox>
                          <Checkbox label="HER2扩增" :disabled="status"></Checkbox>
                          <Checkbox label="PD-1/L1" :disabled="status"></Checkbox>
                          <Checkbox label="肿瘤CTC(循环肿瘤细胞)" :disabled="status"></Checkbox>
                          <Checkbox label="BRCA1/2" :disabled="status"></Checkbox>
                          <Checkbox label="其他" :disabled="status"></Checkbox>
                      </CheckboxGroup>
                    </FormItem>  
                    <FormItem v-show="item.otherArray?item.otherArray.indexOf('其他')!=-1:false">
                        <Input :disabled="status" v-model="item.itsOther" placeholder="请输入其他" />
                    </FormItem>  
                </div>                                                        
            </div>
          </Form>
      </div>
      <div id="part2" v-show="!partShow">
        <Form :model="knubSampleModel" ref="knubSampleModelTwo" :rules="ruleFormTwo">
            <div class="title">物流信息</div>
            <div class="info">
                <FormItem label="快递单号" prop="tKnubSampleEntity.logOrderNum">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.logOrderNum"  placeholder="请输入快递单号" />
                </FormItem>
                    <FormItem label="物流公司">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.logisticsCompany"  placeholder="请输入物流公司" />
                </FormItem>
            </div>
            <div class="title">价格</div>
            <div class="info">
                <FormItem label="促销渠道">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.disChannel"  placeholder="请输入促销渠道" />
                </FormItem>
                <FormItem  label="经销商" >
                    <Select :disabled="moneyStatus"  v-model="knubSampleModel.tKnubSampleEntity.agentid" clearable placeholder="请选择经销商" @on-change="agentChange" >
                        <Option v-for="item in agentList" :value="item.id" :key="item.id" :label="item.agentName "></Option>
                    </Select>
                </FormItem>   
                <FormItem  label="医院" >
                    <Select :disabled="moneyStatus"  v-model="knubSampleModel.tKnubSampleEntity.hospitalid" clearable placeholder="请选择医院" >
                        <Option v-for="item in hospitalList" :value="item.hospitalId" :key="item.hospitalId" :label="item.hospitalName "></Option>
                    </Select>
                </FormItem>  
                  <FormItem label="预付款余额" >
                    <Input :disabled="true" v-model="payment" />
                </FormItem>                      
                <FormItem label="支付方式" prop="tKnubSampleEntity.paymentMethod">
                  <RadioGroup v-model="knubSampleModel.tKnubSampleEntity.paymentMethod">
                    <Radio :disabled="moneyStatus" label="预付">预付</Radio>
                    <Radio :disabled="moneyStatus" label="现付">现付</Radio>                            
                  </RadioGroup>
                </FormItem>                    
                <FormItem label="付款方式" v-show="knubSampleModel.tKnubSampleEntity.paymentMethod=='现付'">
                    <Select :disabled="moneyStatus" v-model="knubSampleModel.tKnubSampleEntity.payment" placeholder="请选择付款方式">
                        <Option :value="parseInt(1)">微信</Option>
                        <Option :value="parseInt(2)">支付宝</Option>
                        <Option :value="parseInt(3)">POS机</Option>
                        <Option :value="parseInt(4)">转账</Option>
                    </Select>
                </FormItem>
                <FormItem label="金额" prop="tKnubSampleEntity.monney">
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.monney"  placeholder="请输入金额" number />
                </FormItem>                    
                <FormItem label="凭证号" v-show="knubSampleModel.tKnubSampleEntity.payment==3">  
                    <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.voucherno" placeholder="请输入凭证号" />
                </FormItem>
            </div>
            <div class="title">备注</div>
            <div class="info suittextarea">
                <Input :disabled="status" v-model="knubSampleModel.tKnubSampleEntity.remark" type="textarea"   placeholder="特殊情况说明(开票信息等)" />
            </div>

            <div class="title">上传附件
                <span class="title-right" v-show="imgInfo.length>0">
                  <Button @click="trashVisible=true" v-if="!trashVisible">删除</Button>
                  <Button @click="trashVisible=false" v-else>取消</Button>
                </span>
            </div>
            <div class="info ">                          
                <div class="demo-upload-list" v-for="(item,index) in imgInfo" :key="index">
                    <img :src="item.src" @click="handleView(index)">                                 
                    <div class="demo-upload-list-cover" v-show="trashVisible">
                        <Icon type="ios-trash-outline" @click.native="handleRemove(index)"></Icon>
                    </div>
    
                    <Modal v-model="item.visible" >
                      <p slot="header">预览</p>
                      <img :src="item.src" style="width: 100%">
                      <div slot="footer"></div>
                    </Modal>   
                </div>
                <Upload
                    ref="upload"
                    :show-upload-list="false"
                    :on-success="uploadSuccess" :on-error="uploadError" 
                    :format="['jpg','jpeg','png']"
                    multiple
                    type="drag"
                    :action="uploadUrl"
                      class="demo-upload-wrap">
                    <div class="demo-upload-camera" >
                        <Icon type="ios-camera" ></Icon>
                    </div>
                </Upload>                        
              </div>                        
          </Form>
      </div>       
    </div>
      
  </div>
</template>

<script>
import topBar from "@/views/component/topbar.vue";
import { sampleData } from "api/index.js";
export default {
  name: "bodycell",
  data() {
    const validateAge = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("年龄不能为空"));
      } else if (!Number.isInteger(value)) {
        callback(new Error("年龄只能输入数字"));
      } else {
        callback();
      }
    };
    const validateMonney = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("金额不能为空"));
      } else if (!Number.isInteger(value)) {
        callback(new Error("金额只能输入数字"));
      } else {
        callback();
      }
    };
    const validateDate = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("采样日期不能为空"));
      } else {
        callback();
      }
    };
    const validateTel = (rule, value, callback) => {
      //是电话号码的情况 010-8788883 或 010/8788883
      if (value) {
        if (value.indexOf("-") != -1 || value.indexOf("/") != -1) {
          if (value && value != "" && !Mcake.isTelNumber(value)) {
            callback(new Error("电话的格式不正确"));
          } else {
            callback();
          }
        } else {
          //如果是手机号码
          if (value != "" && !Mcake.isPhoneNumber(value)) {
            callback(new Error("电话的格式不正确"));
          } else {
            callback();
          }
        }
      } else {
        callback();
      }
    };
    const validateIdCard = (rule, value, callback) => {
      let retIdCard = Mcake.isIdCard(value);
      if (value && value != "" && !retIdCard.state) {
        callback(new Error(retIdCard.msg));
      } else {
        callback();
      }
    };
    const validateOrder = (rule, value, callback) => {
      if (!value || value === "") {
        callback(new Error("快递单号不能为空"));
      } else if (value.length<10 ||value.length>14) {
        callback(new Error("快递单号格式不正确"));
      } else {
        callback();
      }
    };
    return {
      spinShow: false,
      imgInfo: [],
      trashVisible: false,
      firstSaveStatus: false,
      formTitle: "肿瘤个体化用药",
      partShow: true,
      status: true,
      personToggle: true,
      familyToggle: true,
      projectToggle: true,
      moneyStatus:true,
      uploadUrl: "",
      agentList: [],
      hospitalList: [],
      payment: 0, //预付款余额
      knubSampleModel: {
        tKnubSampleEntity: {
          sampleDate: Mcake.getFormateDate(new Date()),
          allImg: [],
          birthday: ""
        },
        tClinicInfoEntity: [
          {
            familyHistory: "",
            cliSampleType: "",
            cliSampleTypeArray: [],
            sampleSource: "",
            masculineDetectionArray: [],
            exceptionalCase: ""
          }
        ],
        tKnubProjectList: [
          {
            pannelArray: [],
            singleCancerArray: [],
            targetedDrugArray: [],
            otherArray: []
          }
        ]
      },
      ruleFormOne: {
        "tKnubSampleEntity.name": {
          required: true,
          message: "姓名不能为空",
          trigger: "blur"
        },
        "tKnubSampleEntity.sex": {
          required: true,
          message: "性别不能为空",
          trigger: "change"
        },
        "tKnubSampleEntity.birthday": {
          required: true,
          validator: validateDate,
          trigger: "change"
        },
        "tKnubSampleEntity.tel": { validator: validateTel, trigger: "blur" },
        "tKnubSampleEntity.idCard": {
          validator: validateIdCard,
          trigger: "blur"
        },
        "tKnubSampleEntity.sampleDate": {
          required: true,
          validator: validateDate,
          trigger: "change"
        },
        "tKnubSampleEntity.ageCancer": {
          required: true,
          validator: validateAge,
          trigger: "blur"
        },
        "tKnubSampleEntity.pathologicDiagnosis": {
          required: true,
          message: "病理诊断不能为空",
          trigger: "blur"
        },
        "tKnubSampleEntity.clinicalStages": {
          required: true,
          message: "临床分期不能为空",
          trigger: "blur"
        },
        "tKnubSampleEntity.detectionResults": {
          required: true,
          message: "既往分子检测结果不能为空",
          trigger: "blur"
        },
        "tKnubSampleEntity.clinicalDiagnosis": {
          required: true,
          message: "临床诊断不能为空",
          trigger: "blur"
        },
        "tKnubSampleEntity.medicineHistory": {
          required: true,
          message: "药物史不能为空",
          trigger: "blur"
        }
      },
      ruleFormTwo: {
        "tKnubSampleEntity.logOrderNum": {
          required: true,
          // message: "快递单号不能为空",
          validator:validateOrder,
          trigger: "blur"
        },
        "tKnubSampleEntity.monney": {
          required: true,
          validator: validateMonney,
          trigger: "blur"
        },
        "tKnubSampleEntity.paymentMethod": {
          required: true,
          message: "支付方式不能为空",
          trigger: "change"
        }
      }
    };
  },
  methods: {
    partToggle(param) {
      this.partShow = param.btnToggle;
    },
    toggleEditStatus() {
      this.status = false;
      if(this.$store.state.btnTemp){
         this.moneyStatus=false;
      }else{
        this.moneyStatus=true;
      }    
    },
    clickNextStep(param) {
      window.scrollTo(0, 0);
      this.$refs["knubSampleModelOne"].validate(valid => {
        if (valid) {
          if (
            this.knubSampleModel.tKnubProjectList[0].pannelArray.length == 0 &&
            this.knubSampleModel.tKnubProjectList[0].singleCancerArray.length ==
              0 &&
            this.knubSampleModel.tKnubProjectList[0].targetedDrugArray.length ==
              0 &&
            this.knubSampleModel.tKnubProjectList[0].otherArray.length == 0
          ) {
            this.$Message.error("检测项目至少要填一项");
          } else {
            this.$refs.topbar.showPartTwo();
          }
        } else {
          this.$Message.error("请把信息填完整");
        }
      });
    },
    saveItem(param) {
      let firstSaveStatus = false;
      this.$refs["knubSampleModelOne"].validate(valid => {
        if (valid) {
          if (
            this.knubSampleModel.tKnubProjectList[0].pannelArray.length == 0 &&
            this.knubSampleModel.tKnubProjectList[0].singleCancerArray.length ==
              0 &&
            this.knubSampleModel.tKnubProjectList[0].targetedDrugArray.length ==
              0 &&
            this.knubSampleModel.tKnubProjectList[0].otherArray.length == 0
          ) {
            this.$Message.error("检测项目至少要填一项");
          } else {
            this.$refs.topbar.showPartTwo();
            firstSaveStatus = true;
          }
        } else {
          this.$Message.error("请把信息填完整");
        }
      });
      if (firstSaveStatus) {
        let obj = this.standardDate(1); //status 0暂存 1保存
        this.$refs["knubSampleModelTwo"].validate(valid => {
          if (valid) {
            //验证通过
            this.tempAndSave(obj);
          } else {
            this.$Message.error("请把信息填完整");
          }
        });
      }
    },
    saveTemp() {
      let obj = this.standardDate(0); //status 0暂存 1保存
      this.tempAndSave(obj);
    },
    standardDate(status) {
      let obj = this.knubSampleModel;
      if (obj.tKnubSampleEntity) {
        obj.tKnubSampleEntity.status = status;
        if (obj.tKnubSampleEntity.birthday == "") {
          obj.tKnubSampleEntity.birthday = null;
        } else {
          obj.tKnubSampleEntity.birthday = Mcake.getFormateDate(
            obj.tKnubSampleEntity.birthday
          );
        }
        if (obj.tKnubSampleEntity.sampleDate == "") {
          obj.tKnubSampleEntity.sampleDate = null;
        } else {
          obj.tKnubSampleEntity.sampleDate = Mcake.getFormateDate(
            obj.tKnubSampleEntity.sampleDate
          );
        }
      }
      return obj;
    },
    tempAndSave(obj) {
      let status = obj.tKnubSampleEntity.status;
      if (this.$store.state.operation == "add") {
        this.spinShow = true;
        sampleData
          .saveBodyCellPerson(obj)
          .then(res => {
            if (res.code == 0) {
              if (status == 0) {
                this.$Message.success("暂存成功");
                this.$router.push("/index");
              } else {
                this.$Message.success("保存成功");
                this.$router.push("/mySample");
              }
            } else if (res.code == 500) {
                this.spinShow = false;
                this.$Message.error(res.msg);
            } else {
              this.$Message.error(res.msg);
            }
          })
          .catch(error => {
            this.$Message.error(error);
          });
      } else {
        this.spinShow = true;
        if (this.$store.state.btnTemp && status == 1) {
          //从暂存到保存，调新增接口扣金额
          sampleData
            .saveBodyCellPerson(obj)
            .then(res => {
              if (res.code == 0) {
                this.$Message.success("保存成功");
                this.$router.push("/mySample");
              } else if (res.code == 500) {
                this.spinShow = false;
                this.$Message.error(res.msg);
              } else {
                this.$Message.error(res.msg);
              }
            })
            .catch(error => {
              this.$Message.error(error);
            });
        } else {
          sampleData
            .updateBodyCellPerson(obj)
            .then(res => {
              if (res.code == 0) {
                if (status == 0) {
                  this.$Message.success("暂存修改成功");
                  this.$router.push("/index");
                } else {
                  this.$Message.success("修改成功");
                  this.$router.push("/mySample");
                }
              } else if (res.code == 500) {
                this.spinShow = false;
                this.$Message.error(res.msg);
              } else {
                this.$Message.error(res.msg);
              }
            })
            .catch(error => {
              this.$Message.error(error);
            });
        }
      }
    },
    getBodyCellInfo() {
      let obj = {
        id: this.$store.state.sampleid
      };
      sampleData
        .getBodyCellPerson(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.knubSampleModel = res.knubSampleModel;
            let showAgentId = this.knubSampleModel.tKnubSampleEntity.agentid;
            if (showAgentId) {
              this.getHospitalListByAgentId(showAgentId);
              this.getAgentById(showAgentId);
            }
            let allImg = this.knubSampleModel.tKnubSampleEntity.allImg;
            if (allImg) {
              //图片不为空才能使用forEach
              allImg.forEach(element => {
                this.imgInfo.push({ src: element, visible: false });
              });
            }
            //为了判断检测项目至少填一项，不能为null
            if (!this.knubSampleModel.tKnubProjectList[0].pannelArray) {
              this.knubSampleModel.tKnubProjectList[0].pannelArray = new Array();
            }
            if (!this.knubSampleModel.tKnubProjectList[0].singleCancerArray) {
              this.knubSampleModel.tKnubProjectList[0].singleCancerArray = new Array();
            }
            if (!this.knubSampleModel.tKnubProjectList[0].targetedDrugArray) {
              this.knubSampleModel.tKnubProjectList[0].targetedDrugArray = new Array();
            }
            if (!this.knubSampleModel.tKnubProjectList[0].otherArray) {
              this.knubSampleModel.tKnubProjectList[0].otherArray = new Array();
            }
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    uploadSuccess(response, file, fileList) {
      if (response.code == 0 || response.code == 200) {
        if (!this.knubSampleModel.tKnubSampleEntity.allImg) {
          //为null需初始化
          this.knubSampleModel.tKnubSampleEntity.allImg = new Array();
        }
        this.knubSampleModel.tKnubSampleEntity.allImg.push(response.msg);
        this.imgInfo.push({ src: response.msg, visible: false });
      } else {
        this.$Message.error(response.msg);
        this.$refs.upload.clearFiles();
      }
    },
    uploadError(error, file, fileList) {
      this.$Message.error(error.msg);
    },
    handleRemove(index) {
      this.knubSampleModel.tKnubSampleEntity.allImg.splice(index, 1);
      this.imgInfo.splice(index, 1);
    },
    handleView(index) {
      this.imgInfo[index].visible = true;
    },
    confirmDate(type){
      var dtPicker = new mui.DtPicker({
        type: "date",
        beginYear: 1860,
        endDate: new Date()
      });
      dtPicker.show(selectItems => {
        if(type=='birthday'){
          this.knubSampleModel.tKnubSampleEntity.birthday = selectItems.text;
          this.$refs.knubSampleModelOne.validateField(
            "tKnubSampleEntity.birthday"
          );
        }
        if(type=='sampleDate'){
          this.knubSampleModel.tKnubSampleEntity.sampleDate = selectItems.text;
          this.$refs.knubSampleModelOne.validateField(
            "tKnubSampleEntity.sampleDate"
          );
        }

      });
    },
    getAgentListByUserId() {
      let obj = {};
      sampleData
        .getAgentListByUserId(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.agentList = res.list;
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    getHospitalListByAgentId(agentId) {
      let obj = {
        agentId: agentId
      };
      sampleData
        .getHospitalListByAgentId(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.hospitalList = res.list;
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    getAgentById(agentId) {
      let obj = {
        id: agentId
      };
      sampleData
        .getAgentById(obj)
        .then(res => {
          if (res.code == 0 || res.code == 200) {
            this.payment = res.agentEntity.payment || 0;
          } else {
            this.$Message.error(res.msg);
          }
        })
        .catch(error => {
          this.$Message.error(error);
        });
    },
    agentChange(agentId) {
      this.knubSampleModel.tKnubSampleEntity.hospitalid = "";
      this.getHospitalListByAgentId(agentId);
      this.getAgentById(agentId);
    }
  },
  mounted() {
    if (this.$store.state.operation == "edit") {
      this.getBodyCellInfo();
      this.status = true;
      this.moneyStatus=true;
    } else {
      this.status = false;
      this.moneyStatus=false;
    }

    this.uploadUrl = this.$store.state.uploadUrl;
    this.getAgentListByUserId();
  },
  components: {
    topBar
  }
};
</script>


